package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ruoyi.system.entity.VitalSigns;
import com.ruoyi.system.mapper.VitalSignsMapper;
import com.ruoyi.system.service.VitalSignsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author ruochen
* @description 针对表【vital_signs(体征数据表)】的数据库操作Service实现
* @createDate 2023-11-19 19:45:33
*/
@Service
public class VitalSignsServiceImpl extends ServiceImpl<VitalSignsMapper, VitalSigns>
    implements VitalSignsService {

    @Resource
    private VitalSignsMapper vitalSignsMapper;

    @Override
    public VitalSigns getVitalSignsByFacilityId(Long vitalId) {

        VitalSigns vitalSigns = vitalSignsMapper.selectById(vitalId);
        if(vitalSigns == null ){
            throw new RuntimeException("体征数据表中没有该设备的数据");
        }
        return vitalSigns;
    }

    @Override
    public List<VitalSigns> getVitalSignsList(VitalSigns vitalSigns) {

        LambdaQueryWrapper<VitalSigns> vitalSignsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        // 按照测量时间倒序排列
        vitalSignsLambdaQueryWrapper.orderByDesc(VitalSigns::getMeasurementDate);
        if (vitalSigns.getUserId()!=null){
            vitalSignsLambdaQueryWrapper.eq(VitalSigns::getUserId,vitalSigns.getUserId());
        }
        if (vitalSigns.getMeasurementDate()!=null){
            vitalSignsLambdaQueryWrapper.like(VitalSigns::getMeasurementDate,vitalSigns.getMeasurementDate());
        }
        if (vitalSigns.getTemperature()!=null){
            vitalSignsLambdaQueryWrapper.eq(VitalSigns::getTemperature,vitalSigns.getTemperature());
        }
        if(vitalSigns.getHeight()!=null){
            vitalSignsLambdaQueryWrapper.eq(VitalSigns::getHeight,vitalSigns.getHeight());
        }
        if (vitalSigns.getWeight()!=null){
            vitalSignsLambdaQueryWrapper.eq(VitalSigns::getWeight,vitalSigns.getWeight());
        }
        if(vitalSigns.getHeight()!=null){
            vitalSignsLambdaQueryWrapper.eq(VitalSigns::getHeight,vitalSigns.getHeight());
        }
        List<VitalSigns> vitalSignsList = vitalSignsMapper.selectList(vitalSignsLambdaQueryWrapper);

        return vitalSignsList;
    }

    @Override
    public List<VitalSigns> getVitalSignsByIsolationId(Long userId) {

        LambdaQueryWrapper<VitalSigns> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(VitalSigns::getUserId,userId);
        // 按照测量时间倒序排列
        lambdaQueryWrapper.orderByDesc(VitalSigns::getMeasurementDate);
        List<VitalSigns> vitalSignsList = vitalSignsMapper.selectList(lambdaQueryWrapper);
        if(vitalSignsList == null || vitalSignsList.size() == 0){
            throw new RuntimeException("体征数据表中没有该设备的数据");
        }
        return vitalSignsList;
    }
}




